package com.qiyuexinxi.chat.util;

import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

/**
 * @program: zjguahao
 * @description: 密码加密
 * @author: meco.he
 * @create: 2018/12/28 09:45
 **/
@Slf4j
public class EncryptUtil {

    public static String encryptPWD(String pwd, String salt){
        MD5 md5 = new MD5();
        String ps = pwd + salt;
        String mdPs = md5.getMD5ofStr(ps);
        return mdPs;
    }

    public static String encryptToken(String userId, String userKey){
        String token = null;
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        try{
            token = AESUtil.encryptToken(uuid + "_" + userId, "", userKey);
        } catch (Exception e){
            log.error(e.getMessage());
        }
        return token;
    }

    public static String decryptToken(String token, String userKey){
        String tokenId = null;
        try{
            tokenId = AESUtil.decryptToken(token, "", userKey);
        } catch (Exception e){
            log.error(e.getMessage());
        }
        return tokenId;
    }

}
